﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ResponseMonitor
{
    public class Logger
    {
        private static string _logPath = string.Empty;

        public static void Init()
        {
            _logPath = Settings.Default.LogPath;
            if (!Directory.Exists(_logPath))
                Directory.CreateDirectory(_logPath);
        }

        public static void w(string s)
        {
            string fileName = DateTime.Now.ToString("yyyyMMdd_HH");
            string filePath = _logPath + @"\" + fileName;

            using (StreamWriter sw = new StreamWriter(filePath, true, Encoding.Default))
            {
                sw.WriteLine(s);
                sw.WriteLine("================================" + DateTime.Now.ToString());
            }
        }

        public static void w(Exception ex)
        {
            w(ex.ToString());
        }

        public static void w(Exception ex, string s)
        {
            string content = s + "\r\n" + ex.ToString();
            w(content);
        }
    }
}
